//****************************************************************
// Autor:   Yimy Juarez 
//          Gustavo Castro
//          Ulil Coqti
//          Josué Barrientos
//       
// Seccion: 10
// Nombre del Archivo: CircularList.java
// Fecha de Modificacion:08/08/2012
// Descripcion:
// Clase de implementación de la lista de forma circular
// ***************************************************************
package hojadetrabajo4;

import java.util.Iterator;

public class CircularList<E> extends abstractList<E> {
    protected Node<E> tail;
    protected int count;

    public CircularList()
    // pre: constructs a new circular list
    {
    tail = null;
    count = 0;
    }

    public void addFirst(E value)
    // pre: value non-null
    // post: adds element to head of list
    {
    Node<E> temp = new Node<E>(value);
    if (tail == null) { // first value added
        tail = temp;
        tail.setNext(tail);
    } else { // element exists in list
        temp.setNext(tail.next());
        tail.setNext(temp);
    }
    count++;
    }


    public void addLast(E value)
    // pre: value non-null
    // post: adds element to tail of list
    {
    // new entry:
    addFirst(value);
    tail = tail.next();
    }


    // lo dificil es quitar el elemento de la cola

    public E removeLast()
    // pre: !isEmpty()
    // post: returns and removes value from tail of list
    {
        Node<E> finger = tail;
        while (finger.next() != tail) {
            finger = finger.next();
        }
        // finger now points to second-to-last value
        Node<E> temp = tail;
        if (finger == tail)
        {
            tail = null;
        } else {
            finger.setNext(tail.next());
            tail = finger;
        }
        count--;
        return temp.value();
    }
    
      public void clear()
   // post: empties list
   {
   }


   public E getFirst()
   // pre: list is not empty
   // post: returns first value in list
   {
       return null;
   }        
   
   public E getLast()
   // pre: list is not empty
   // post: returns last value in list
   {
       return null;
   }
           
   public E removeFirst()
   // pre: list is not empty
   // post: removes first value from list
   {
       return null;
   }
           

   public E remove(E value)
   // post: removes and returns element equal to value
   // otherwise returns null
   {
       return null;
   }

   public void add(E value)
   // post: value is added to tail of list
   {
       
   }

   public E remove()
   // pre: list has at least one element
   // post: removes last value found in list
   {
       return null;
   }

   public E get()
   // pre: list has at least one element
   // post: returns last value found in list
   {
       return null;
   }
 

   public int indexOf(E value)
   // pre: value is not null
   // post: returns (0-origin) index of value,
   // or -1 if value is not found
   {
       return 0;
   }

   public int lastIndexOf(E value)
   // pre: value is not null
   // post: returns (0-origin) index of value,
   // or -1 if value is not found
   {
       return 0;
   }

   public E get(int i)
   // pre: 0 <= i < size()
   // post: returns object found at that location
   {
       return null;
   }

   public E set(int i, E o)
   // pre: 0 <= i < size()
   // post: sets ith entry of list to value o;
   // returns old value
   {
       return null;
   }
           
   public void add(int i, E o)
   // pre: 0 <= i <= size()
   // post: adds ith entry of list to value o
   {
   }

   public E remove(int i)
   // pre: 0 <= i < size()
   // post: removes and returns object found at that location
   {
       return null;
   }

   public Iterator<E> iterator()
   // post: returns an iterator allowing
   // ordered traversal of elements in list
   {
       return null;
   }

    public int size() {
        return count;
    }
}

    

